package com.sourcetrip.binarytree;


import com.sourcetrip.raw.adt.MyBinarySearchTree;
import com.sourcetrip.raw.adt.MyBinarySearchTree2;
import com.sourcetrip.utils.printer.BinaryTrees;

/**
 * @author: ZhouBert
 * @date: 2020/11/25
 * @description:
 */
public class MyBinarySearchTreeTest02 {

	public static void main(String[] args) {
		//testBigNSearch();
		tesstRemove();

//		MyBinarySearchTree2<Integer> binarySearchTree = new MyBinarySearchTree2<>();
//		binarySearchTree.add(10);
//		binarySearchTree.add(5);
//		binarySearchTree.add(3);
//		binarySearchTree.add(4);
//		binarySearchTree.add(15);
//		binarySearchTree.add(13);
//		binarySearchTree.add(14);
//		System.out.println(binarySearchTree.toString());
	}

	/**
	 * 改成 循环之后，马上就出来结果了！
	 */
	static void testBigNSearch() {
		MyBinarySearchTree2<Integer> tree = new MyBinarySearchTree2<>();
		for (int i = 0; i < 10000; i++) {
			tree.add(i);
		}
		System.out.println("begin:" + System.currentTimeMillis());
		boolean contains = tree.contains(9999);
		System.out.println("contains = " + contains);
		System.out.println("tree = " + tree);
		System.out.println("end:" + System.currentTimeMillis());
	}

	static void tesstRemove() {
		Integer data[] = new Integer[]{
				67, 52, 92, 96, 53, 95, 13, 63, 34, 82, 76, 54, 9, 68, 39
		};
		data = new Integer[]{
				85, 19, 3, 7, 99, 95, 2, 1, 70, 44, 58, 11, 21, 14, 93, 57, 4, 56
		};

		MyBinarySearchTree<Integer> bst = new MyBinarySearchTree<>();
		for (int i = 0; i < data.length; i++) {
			bst.add(data[i]);
//			System.out.println("【" + data[i] + "】");
//			BinaryTrees.println(bst);
//			System.out.println("---------------------------------------");
		}

		BinaryTrees.println(bst);
		for (int i = 0; i < data.length; i++) {
			bst.remove(data[i]);
			System.out.println("【" + data[i] + "】");
			BinaryTrees.println(bst);
			MyBinarySearchTree.inorderPrintTree(bst);
			System.out.println();
			System.out.println("---------------------------------------");
		}


	}
}
